﻿using System;
using System.Reflection;
using NHibernate;
using NHibernate.Cfg;
using NLipsum.Core;

namespace Myotragus.Data.Tupples.Tests
{
	public class Core
	{
		public static ISessionFactory Factory { get; private set; }
		public static ISession OpenSession()
		{
			Initialize();
			return Factory.OpenSession();
		}

		private static bool _initialized;
		public static void Initialize()
		{
			if (_initialized)
				return;

			var cfg = new Configuration();
			cfg.Configure();
			cfg.AddAssembly(Assembly.GetExecutingAssembly());
			Factory = cfg.BuildSessionFactory();

			_initialized = true;
		}

		private readonly static Random Generator = new Random();

		public static int GetRandom(int max)
		{
			return Generator.Next(max);
		}

		public static string GenerateSentence()
		{
			return GenerateSentence(1);
		}

		public static string GenerateSentence(int count)
		{
			return LipsumGenerator.Generate(count, Features.Sentences, "{0}", Lipsums.LoremIpsum);
		}
	}
}